$(document).ready(function() {
    $('#membership_chpass').submit(updatePass);
})


function updatePass() {
    var oldPass      = $('#old_pass').val();
    var newPass      = $('#new_pass').val();
    var newPassAgain = $('#new_pass_again').val();
    var websiteUrl   = $('#website_url').val();
    $.ajax({
	url        : websiteUrl + 'sys/backend_member/updatepass',
	type       : 'post',
	dataType   : 'json',
	data       : {
	    oldPass      : oldPass,
            newPass      : newPass,
            newPassAgain : newPassAgain
	},
	beforeSend : function() {
            $('#imsg').removeClass('errors');
            $('#imsg').removeClass('success');
            $('#imsg').addClass('success');
            $('#imsg').html('Working, please wait...');
            $('#imsg').show();
	},
	error      : function() {
            alert('Something went wrong');
	},
	success    : function(data) {
            if(data.error == 1) {
                $('#imsg').addClass('errors');
                $('#imsg').html(data.msg);
                return;
            }
            else {
                $('#imsg').removeClass('errors');
                $('#imsg').addClass('success');
                $('#imsg').html('Password changed.');
            }
	},
	complete   : function() {
	    
	}
    })
    return false;
}